import path from 'node:path';
import { app } from 'electron';
import { Config } from '@p/main-config';
import { initConfigFile, checkConfigFileValue, configFileDefaultValue } from './configFile';
import { __path } from '@e/methods/path';

export const config: Config = {
	windowDefaultSize: {
		width: 1280,
		height: 720,
	},
	getWindowloadValue() {
		if (this.isDevEnv()) {
			return 'http://localhost:6008';
		} else {
			return path.join(__dirname, './page/index.html');
		}
	},
	getEnv() {
		if (app.isPackaged) {
			return 'production';
		} else {
			return 'development';
		}
	},
	isDevEnv() {
		return this.getEnv() === 'development';
	},
	isProEnv() {
		return this.getEnv() === 'production';
	},
	getInstallPath() {
		// 根据环境变量返回不同的路径
		if (this.isDevEnv()) {
			let installPath = path.join(process.cwd(), 'temp_install');

			__path.mkdirIfExist(installPath);

			return installPath;
		} else {
			return path.dirname(app.getPath('exe'));
		}
	},
	getResourcesPath() {
		const dirPath = path.join(this.getInstallPath(), 'resources');

		if (this.isDevEnv()) {
			__path.mkdirIfExist(dirPath);

			return dirPath;
		} else {
			return dirPath;
		}
	},
	getSystemCoding() {
		if (process.env.LANG) {
			return process.env.LANG.split('.')[1];
		} else {
			return 'utf-8';
		}
	},
	getName() {
		return app.getName();
	},
	getVersion() {
		return app.getVersion();
	},
	checkConfigFileValue,
	configFileDefaultValue,
	configFile: initConfigFile(app.getPath('userData')),
};
